package com.itbuka.vip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.itbuka.vip.domain.VipEvaluate;
import com.itbuka.vip.mapper.VipEvaluateMapper;
import com.itbuka.vip.service.VipEvaluateService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


import java.util.List;

/**
 * @author ld
 * @description 针对表【vip_evaluate】的数据库操作Service实现
 * @createDate 2024-07-29 14:47:01
 */
@Service
public class VipEvaluateServiceImpl implements VipEvaluateService {
    @Autowired
    private VipEvaluateMapper vipEvaluateMapper;

    @Override
    public List<VipEvaluate> selectAll() {
        LambdaQueryWrapper<VipEvaluate> lqw = new LambdaQueryWrapper<>();
        lqw.eq(VipEvaluate::getIsDelete, 0);
        return vipEvaluateMapper.selectList(lqw);
    }


    @Override
    public List<VipEvaluate> selectList(VipEvaluate vipEvaluate) {
        LambdaQueryWrapper<VipEvaluate> lqw = this.lqw(vipEvaluate);
        return vipEvaluateMapper.selectList(lqw);
    }

    @Override
    public Integer insert(VipEvaluate vipEvaluate) {
        return vipEvaluateMapper.insert(vipEvaluate);
    }

    @Override
    @Transactional
    public Integer delete(String ids) {
        try {
            String[] split = ids.split(",");
            for (String id : split) {
                VipEvaluate vipEvaluate = new VipEvaluate();
                vipEvaluate.setId(Long.parseLong(id));
                vipEvaluate.setIsDelete(1);
                vipEvaluateMapper.updateById(vipEvaluate);
            }
            return 1;
        } catch (Exception e) {
            return -1;
        }
    }

    @Override
    public Integer update(VipEvaluate vipEvaluate) {
        return vipEvaluateMapper.updateById(vipEvaluate);
    }

    @Override
    public Page<VipEvaluate> pageAll(Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return (Page<VipEvaluate>) this.selectAll();
    }

    @Override
    public Page<VipEvaluate> pageList(VipEvaluate vipEvaluate, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return (Page<VipEvaluate>) this.selectList(vipEvaluate);
    }

    @Override
    public Integer status(Long id, Integer status) {
        if (id == null) {
            return -1;
        }
        if (!(status == 0 || status == 1)) {
            return -2;
        }
        VipEvaluate vipEvaluate = new VipEvaluate();
        vipEvaluate.setId(id);
        vipEvaluate.setStatus(status);
        return vipEvaluateMapper.updateById(vipEvaluate);
    }

    public LambdaQueryWrapper<VipEvaluate> lqw(VipEvaluate vipEvaluate) {
        LambdaQueryWrapper<VipEvaluate> lqw = new LambdaQueryWrapper<>();
        if (vipEvaluate.getId() != null) {
            lqw.eq(VipEvaluate::getId, vipEvaluate.getId());
        }
        if (vipEvaluate.getGoodsName() != null) {
            lqw.eq(VipEvaluate::getGoodsName, vipEvaluate.getGoodsName());
        }
        if (vipEvaluate.getVipName() != null) {
            lqw.eq(VipEvaluate::getVipName, vipEvaluate.getVipName());
        }
        if (vipEvaluate.getEvaluateType() != null) {
            lqw.eq(VipEvaluate::getEvaluateType, vipEvaluate.getEvaluateType());
        }
        if (vipEvaluate.getLogisticsRating() != null) {
            lqw.eq(VipEvaluate::getLogisticsRating, vipEvaluate.getLogisticsRating());
        }
        if (vipEvaluate.getServiceRating() != null) {
            lqw.eq(VipEvaluate::getServiceRating, vipEvaluate.getServiceRating());
        }
        if (vipEvaluate.getEvaluateTime() != null) {
            lqw.eq(VipEvaluate::getEvaluateTime, vipEvaluate.getEvaluateTime());
        }
        if (vipEvaluate.getStatus() != null) {
            lqw.eq(VipEvaluate::getStatus, vipEvaluate.getStatus());
        }
        if (vipEvaluate.getIsDelete() != null) {
            lqw.eq(VipEvaluate::getIsDelete, vipEvaluate.getIsDelete());
        }
        if (vipEvaluate.getCreateTime() != null) {
            lqw.eq(VipEvaluate::getCreateTime, vipEvaluate.getCreateTime());
        }
        if (vipEvaluate.getUpdateTime() != null) {
            lqw.eq(VipEvaluate::getUpdateTime, vipEvaluate.getUpdateTime());
        }
        return lqw;
    }
}




